package com.cskaoyan.session;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import java.io.IOException;

/**
 * @author Macro_Ray
 * @since 2024/5/2 上午9:53
 */
@WebServlet("/ss1")
public class SessionServlet1 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        HttpSession session = req.getSession();
        // 额外创建一个Cookie，用于保存SessionID
        Cookie cookie = new Cookie("JSESSIONID",session.getId());
        cookie.setMaxAge(180);
        resp.addCookie(cookie);
        session.setAttribute("username","admin123");
    }
}
